﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PEIS.tjjg;
using PEIS.main;
using Encrypt;

namespace PEIS
{
    public partial class Form_login_zy : Form
    {
        xtBiz xtbiz = new xtBiz();
        xtggBiz xtggbiz = new xtggBiz();
        loginBiz loginbiz = new loginBiz();
        Jiami jm = new Jiami();
        Rijndael_ rijndael_ = new Rijndael_();
        public Form_login_zy()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            //Form_zywj_out frm = new Form_zywj_out();

            ZY_MainForm frm = new ZY_MainForm();
            frm.Show();
            this.Hide();
        }

        private void Form_login_zy_Load(object sender, EventArgs e)
        {
            #region 注册判断
            DataTable dt_xt_reg = xtggbiz.Get_xt_reg();
            if (dt_xt_reg.Rows.Count > 0)//注册了，判断是否过期，及用户数的问题
            {
                string str_code = dt_xt_reg.Rows[0]["reg"].ToString().Trim();
                string str_yhmc = "";
                string str_jzrq = "";
                string str_yhsl = "";
                try
                {
                    str_code = jm.DecryptDES(str_code, "@xxsoft@");
                    str_yhmc = str_code.Split('|')[1];
                    str_jzrq = str_code.Split('|')[3];
                    str_yhsl = str_code.Split('|')[2];
                }
                catch
                {
                    MessageBox.Show("系统注册码异常，请联系供应商：15923051230！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Program.sfzc = false;
                    Form_reg frm = new Form_reg();
                    frm.ShowDialog();
                    return;
                    //Application.Exit();
                }
                string str_tjdw = xtbiz.GetXtCsz("TjDwMc");//单位名称
                if (str_tjdw != str_yhmc)//体检单位名称不一致
                {
                    Program.sfzc = false;
                }
                Program.reg_dwmc = str_yhmc;

                str_yhsl = new Common.Common().CharConverter(str_yhsl);
                if (str_yhsl == "") str_yhsl = "0";
                //当用户数量大于的时候关闭应用程序
                if (Convert.ToInt32(loginbiz.Get_Yhsl()) > Convert.ToInt32(str_yhsl))
                {
                    MessageBox.Show("系统超过许可数量，请联系供应商：15923051230！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Program.sfzc = false;
                    Application.Exit();
                }

                //没有过期的时候
                if (Convert.ToDateTime(str_jzrq) < xtbiz.GetServerDate())
                {
                    Program.sfzc = false;
                    MessageBox.Show("系统已经到期，请联系供应商：15923051230！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    Program.sfzc = true;
                    if (Convert.ToDateTime(str_jzrq) < xtbiz.GetServerDate().AddDays(7))
                    {
                        MessageBox.Show("系统快要到期，为了不影响您的使用，请联系供应商！\n到期日期：" + str_jzrq, "提示",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                if (loginbiz.GetNowDate() < loginbiz.GetMaxDjrq().AddDays(-1))//用户擅自修改系统日期
                {
                    Program.sfzc = false;
                    MessageBox.Show("日期已倒退，请检查！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else//没有注册
            {
                Program.sfzc = false;
            }
            #endregion
        }
    }
}
